package com.suixinsanren.design.compound.demo01;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Observable implements QuackObservable {

    public List<Observer> observerList = new ArrayList<>();
    public QuackObservable duck;

    public Observable(QuackObservable duck) {
        this.duck = duck;
    }

    @Override
    public void registerObserver(Observer observer) {
        observerList.add(observer);
    }

    @Override
    public void notifyObservers() {
        observerList.forEach(observer -> observer.update(duck));
    }

    public Iterator<Observer> getObservers() {
        return observerList.iterator();
    }

}
